<%@ page language="java" contentType="text/html; charset=UTF-8"  pageEncoding="UTF-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@taglib prefix="l" uri="/lion-taglib" %>
<!doctype html>
<html lang="en">
<head>
	<meta charset="UTF-8" />
	<style type="text/css">
		.file_list{padding: 0;margin: 0;list-style: none;max-height: 60px;overflow: auto;}
		.file_list li{float: :left;border:solid 1px #ccc;padding: 2px 5px;margin-right: 10px;float: left;line-height: 20px;margin-bottom: 5px;text-indent: 0;}
		.file_list li a{ width: 70px;text-overflow: ellipsis;margin-right:10px;overflow: hidden;display: inline-block;white-space: nowrap;text-decoration: underline;}
	</style>
	<script type="text/javascript">
		
		$(function(){
			var tree = new S.Tree({
				el:'#proj_models_tree',
				ds:'${webcontext }/${pathvar.admin}/br/project/modules/list?projectId=${projectId}',
				render:function(node){
					return '<a class="icons brick"></a> '+node.name;
				},
				loaded:function(){
					tree.setChecked(['${bug.modelId}']);
				},
				click:function(node){
					$('#pmodelId').val(node.data.id);
				}
			});
			
			new S.AutoComplete({
				el:'#bug_owner',
				url:'${webcontext}/${pathvar.admin}/user/search',
				render:function(data){
					return '<b>'+data.realName+'</b> <span>'+data.orgName+'</span>';
				},
				click:function(data){
					$('#bug_owner').val(data.realName+'('+data.orgName+')');
					$('#bug_owner').attr('readonly','readonly');
					$('#bug_owner').parent().parent().append('<i class="sclose">x</i>');
					$('#bugowner').val(data.id);
				}
			});
			
			$('#bug_owner').closest('td').delegate('.sclose','click',function(){
				$('#bugowner').val('');
				$(this).remove();
				$('#bug_owner').removeAttr('readonly').val('');
			});	
			
			//attachment
			var files = new S.List();
			function fileChanged(){
				var fls = $('#attachIds').val().split(',');
				if(fls.length>0){
					S.each(fls,function(i,f){
						files.each(function(j,e){
							if(e.id == f){
								files.removeAt(j);
							}
						});
					});
				}
				if(files.isEmpty()){return;}
				var ids = [];
				files.each(function(i,f){
					ids.push(f.id);
				});
				S.each(fls,function(i,f){
					if(f!=''){ids.push(f);}
				});
				$('#attachIds').val(ids.join(','));
				
				var html = [];
				files.each(function(i,f){
					html.push('<li><a title="'+f.name+'" onclick="openFile('+f.id+')">'+f.name+'</a><i class="sclose" onclick="removeFile('+f.id+',this)">x</i></li>');
				});
				$('#attach_list').append(html.join(''));
				
			}
			
			$('#btn_select_file').click(function(){
				var dlg = new S.Dialog({
				 	title:'选择文件',
				 	width:700,
				 	height:550,
				 	modal:true,
				 	url:'${webcontext}/${pathvar.admin}/mc/file/choosefile',
				 	buttons:{
				 		'插入':function(){
				 			var items = fileChooserTbl.getCheckedRow();
				 			if(items.length ==0){new S.Info({text:'未选择文件',type:'warn'}).show();return;}
				 			files.clear();
				 			S.each(items,function(i,f){
				 				files.add(f);
				 			});
				 			fileChanged();
				 			new S.Info({text:'文件已加入',type:'success'}).show();
				 			this.remove();
				 		},
				 		'关闭':function(){
				 			this.remove();
				 		}
				 	}
				 });
				 dlg.show();
			});
		});
		
		function removeFile(id,t){
			var fls = $('#attachIds').val().split(',');
			S.each(fls,function(i,f){
				if(f == id){
					fls.splice(i,1);
					return false;
				}
			});
			$('#attachIds').val(fls.join(','));
			$(t).closest('li').remove();
		}
		
		function openFile(id){
			window.open('${webcontext}/${pathvar.admin}/mc/file/get?id='+id);
		}
	</script>
</head>
<body>
	<div class="filled-box">
		<div class="sidebar" style="width: 250px">
			<div class="toolbar">
				<span class="btn" >项目模块</span>			
			</div>
			<div class="content" id="proj_models_tree">
				
			</div>
		</div>
		<div class="rightside" style="margin-left: 250px">
			<div class="toolbar">
				<c:if test="${bug!=null }">　<span class="btn">Bug　#${bug.id }</span></c:if>
			</div>
			<div class="content">
				<form>
					<input type="hidden" name="id" value="${bug.id}">
					<input type="hidden" name="owner" value="${bug.owner}" id="bugowner">
					<input type="hidden" name="modelId" value="${bug.modelId}" id="pmodelId">
					<input type="hidden" name="projectId" value="${bug.projectId}">
					<input type="hidden" name="attachs" value="${bug.attachs }" id="attachIds">
					<table width="100%">
						<tr>
							<td width="100">标题：</td>
							<td><input type="text" class="huge" name="title" check="required" value="${bug.title }"></td>
						</tr>
						<tr>
							<td >指派给：</td>
							<td>
							<c:choose>
								<c:when test="${owner!=null }"><input type="text"  id="bug_owner" readonly="readonly" value="${owner.realName }"><i class="sclose">x</i></c:when>
								<c:otherwise><input type="text" id="bug_owner" ></c:otherwise>
							</c:choose>
							</td>
						</tr>
						<tr>
							<td></td>
							<td>
								 <span>状态 <select check="required" name="bugStatus">
									<option value="1" ${bug.bugStatus==1?'selected="selected"':'' } >打开</option>
									<option value="2" ${bug.bugStatus==2?'selected="selected"':'' }>已解决</option>
									<option value="3" ${bug.bugStatus==3?'selected="selected"':'' }>关闭</option>
								</select></span> 
								 <span>等级 <select check="required" name="level">
									<option></option>
									<option value="1" ${bug.level==1?'selected="selected"':'' }>系统缺陷</option>
									<option value="2" ${bug.level==2?'selected="selected"':'' }>模块缺陷</option>
									<option value="3" ${bug.level==3?'selected="selected"':'' }>功能缺陷</option>
									<option value="4" ${bug.level==4?'selected="selected"':'' }>常识缺陷</option>
									<option value="5" ${bug.level==5?'selected="selected"':'' }>建议性</option>
								</select></span>
								 <c:if test="${bug!=null }">
								 <span>解决方式 <select name="solveType">
								 	<option value=""> </option>
									<option value="1" ${bug.solveType==1?'selected="selected"':'' }>修改程序</option>
									<option value="2" ${bug.solveType==2?'selected="selected"':'' }>修改数据库</option>
									<option value="3" ${bug.solveType==3?'selected="selected"':'' }>调整运行环境</option>
									<option value="4" ${bug.solveType==4?'selected="selected"':'' }>调整操作流程</option>
									<option value="5" ${bug.solveType==5?'selected="selected"':'' }>有意为之</option>
									<option value="6" ${bug.solveType==6?'selected="selected"':'' }>无法重现</option>
									<option value="7" ${bug.solveType==7?'selected="selected"':'' }>误报</option>
									<option value="8" ${bug.solveType==8?'selected="selected"':'' }>特例</option>
									<option value="9" ${bug.solveType==9?'selected="selected"':'' }>转为新需求</option>
									<option value="10" ${bug.solveType==10?'selected="selected"':'' }>不处理</option>
									<option value="11" ${bug.solveType==11?'selected="selected"':'' }>其他处理方式</option>
								</select></span>
								 </c:if>
							</td>
						</tr>
						<tr>
							<td>描述</td>
							<td><textarea name="description" rows="30" cols="10" style="height:200px;width: 500px;">${bug.description }</textarea></td>
						</tr>
						<c:if test="${bug!=null }">
						<tr>
							<td>处理日志</td>
							<td><div style="max-height:200px;width:500px;overflow-y: auto;" >${l:escapeNoBr(bug.logs)}</div></td>
						</tr>
						</c:if>
						<tr>
							<td colspan="2" style="text-align: left;">附件：<span class="btn" id="btn_select_file"><a class="icons email_attach"></a> 附件</span><input multiple="multiple" type="file" id="select_file" style="display: none;"></td>
						</tr>
						<tr>
							<td colspan="2"  style="text-align: left;">
								<ul class="file_list" id="attach_list" style="margin-bottom: 10px;">
									<c:forEach items="${attaches }" var="f">
										<li ><a href="#" title="${f.name }" onclick="openFile(${f.id})">${f.name }</a><i class="sclose" onclick="removeFile(${f.id},this)">x</i></li>
									</c:forEach>
								</ul>
							</td>
						</tr>
					</table>
				</form>				
			</div>
		</div>
	</div>
</body>
</html>